import api from '../../api/index'
import {
    formatTime
} from '../../utils/util'
Page({
    data: {
        list: [],
        fraction: 0,
        intervalTime: "00:00",
        len: 0,
        wrongLen: 0
    },
    async onLoad(option) {
        let list = JSON.parse(option.list)
        // await api.postBadproblem(JSON.stringify(list)).then(res => {
        //     console.log(res);
        // })
        let intervalTime = option.intervalTime
        this.setData({
            list: list,
            wrong: [],
            intervalTime: intervalTime
        })
        this.getFraction()
        this.addWrong()
    },
    // 重新考试
    again() {
        wx.navigateBack({
            delta: 0,
        })
    },
    getFraction() {
        let list = this.data.list
        let count = 0
        let wrong = []
        list.forEach(item => {
            if (item.type == item.choose) {
                count++
            } else {
                wrong.push(item)
            }
        })
        this.setData({
            fraction: count * 10,
            wrong: wrong,
            wrongLen: wrong.length,
            len: list.length
        })


    },
    // 增加错题
    addWrong() {
        let datijilu = wx.getStorageSync('datijilu')
        let wrongList = {
            intervalTime: this.data.intervalTime,
            wrongList: this.data.wrong,
            integral: this.data.fraction
        }
        // 答题记录
        let date = formatTime(new Date())
        let res = {
            historyIntegral: this.data.fraction,
            historyIntervalTime: this.data.intervalTime,
            historyDate: date
        }
        datijilu.push(res)
        console.log(datijilu);
        wx.setStorageSync('datijilu', datijilu)
        wx.setStorageSync('wrongList', wrongList)
        // console.log(wrongList);
    }
})